﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using FineUIPro;

namespace CanDoo.Oil.WebApp.proWarehouse
{
    public partial class Edit : EditPagebase<IWarehouseContract, Warehouse>
    {
        public IWarehouseTypeContract WarehouseTypeContract { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //FineUIListHelper.BindDDL<WarehouseType>(WarehouseTypeContract.GetResolvedTree(), 0L, ed_WarehouseType,true);
                FineUIListHelper.BindDDL(WarehouseTypeContract.EntityName, this.WarehouseTypeContract.GetSelectList(), 0L, ed_WarehouseType,true);
                if (PageMode != pagemode.Add)
                    LoadData();
            }
        }

        protected override void LoadData(Warehouse entity)
        {
            ed_Name.SetValue(entity.Name);
            ed_Code.SetValue(entity.Code);
            if (!entity.WarehouseTypeId.IsNull())
                ed_WarehouseType.SetValue(entity.WarehouseTypeId);
            ed_Manager.SetValue(entity.Manager);
            ed_Tel.SetValue(entity.Tel);
            ed_Address.SetValue(entity.Address);
            ed_Remark.SetValue(entity.Remark);
        }

        protected override OperationResult SaveData(Warehouse entity)
        {
            entity.Name = ed_Name.GetValue().ToString();
            entity.Code = ed_Code.GetValue().ToString();
            if (ed_WarehouseType.GetValue().ToLong() == 0L)
                entity.WarehouseTypeId = 0L;
            else
                entity.WarehouseTypeId = ed_WarehouseType.GetValue().ToLong();
            entity.Manager = ed_Manager.GetValue().ToString();
            entity.Tel = ed_Tel.GetValue().ToString();
            entity.Address = ed_Address.GetValue().ToString();
            entity.Remark = ed_Remark.GetValue().ToString();
            return base.SaveData(entity);
            
        }
    }
}
